package com.rocksdata.mc.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.ctz.commonframe.ui.TitleBarActivity;
import com.rocksdata.mc.business.BusinessManager;
import com.rocksdata.mc.Constant;
import com.rocksdata.mc.R;
import com.rocksdata.mc.entity.TeacherContactInfo;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.List;

/**
 * Created by 陈堂正 on 2017/4/11.
 */

@ContentView(R.layout.activity_select_department)
public class SelectDepartmentActivity extends TitleBarActivity {
    @ViewInject(R.id.lv_department)
    private ListView lvDepartment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleMiddleText("选择部门");

        final List<TeacherContactInfo> list = BusinessManager.getUserInfoManager().getTeacherList();
        lvDepartment.setAdapter(new ArrayAdapter<TeacherContactInfo>(this, android.R.layout.simple_list_item_1, list));
        lvDepartment.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TeacherContactInfo info = list.get(position);
                Intent intent = new Intent();
                intent.putExtra(Constant.EXTRA_KEY_SELECTED_DEPARTMENT_ID, info.getDepartmentCode());
                intent.putExtra(Constant.EXTRA_KEY_SELECTED_DEPARTMENT_NAME, info.getDepartmentName());
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
